package flc.ast.adapter;


import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.stark.picselect.entity.SelectMediaEntity;

import flc.ast.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.basic.utils.TimeUtil;

public class SelVideoAdapter extends StkProviderMultiAdapter<SelectMediaEntity> {


    public SelVideoAdapter() {
        addItemProvider(new StkSingleSpanProvider(126));
        addItemProvider(new SelVideoProvider());
    }

    private class SelVideoProvider extends BaseItemProvider<SelectMediaEntity> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_sel_video;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, SelectMediaEntity bean) {
            if (bean.getPath() == null) {
                baseViewHolder.setImageResource(R.id.ivSelVideoItemImg, R.drawable.kp_ps);
                baseViewHolder.getView(R.id.ivSelVideoItemSel).setVisibility(View.GONE);
                baseViewHolder.getView(R.id.ivSelVideoItemBg).setVisibility(View.GONE);
            } else {
                Glide.with(getContext()).load(bean.getPath())
                        .into((ImageView) baseViewHolder.getView(R.id.ivSelVideoItemImg));
                baseViewHolder.setText(R.id.tvSelVideoItemTime, TimeUtil.getMmss(bean.getDuration()));
                baseViewHolder.getView(R.id.ivSelVideoItemBg).setVisibility(View.VISIBLE);
                if (bean.isChecked()) {
                    baseViewHolder.setImageResource(R.id.ivSelVideoItemSel, R.drawable.icon_gx1);
                } else {
                    baseViewHolder.setImageResource(R.id.ivSelVideoItemSel, R.drawable.icon_gx1a);
                }
            }
        }
    }

}
